//
//  HSWebViewController.swift
//  HomeSchoolDemo
//
//  Created by Mac on 16/10/8.
//  Copyright © 2016年 chendong. All rights reserved.
//

import UIKit
import WebKit

class HSWebViewController: UIViewController {
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupTopUI()
        view.backgroundColor = UIColor.white
        addwebView()
    }

    func setupTopUI() {
        //模拟一个假导航栏
        let navVc = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 64))
        navVc.backgroundColor = UIColor().colorWithHex(0x009ee7)
        view.addSubview(navVc)
        //返回按钮
        let back = UIButton(frame: CGRect(x: 8, y: 16, width: 70, height: 48))
        back.setImage(UIImage(named:"返回按钮"), for: .normal)
        back.addTarget(self, action: #selector(backBtnClicked), for: .touchUpInside)
        navVc.addSubview(back)
        //文字
        let label = UILabel(frame: CGRect(x: 60, y: 16, width: 150, height: 48))
        label.text = "百度首页"
        label.textColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        label.font = UIFont.systemFont(ofSize: 20)
        
        navVc.addSubview(label)
    }
    
    func backBtnClicked()  {
        dismiss(animated: true, completion: nil)
    }
    
    func addwebView() {
        let webView = WKWebView(frame: CGRect(x: 0, y: 64, width: self.view.frame.width, height: self.view.frame.height-64))
        //webView.navigationDelegate = self.view as! WKNavigationDelegate?
        
        let request = URLRequest(url: URL(string: "https://www.baidu.com")!)
        webView.load(request)
        view.addSubview(webView)
    }
    
    
}
